package com.woniuxy.intellihome.mapper;

import com.woniuxy.intellihome.entity.GoodsSpu;
import com.woniuxy.intellihome.entity.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
public interface SkuMapper extends BaseMapper<Sku> {

    /**
     * 根据spu id获取下属所有的sku
     *
     * @param spuId spu的Id
     * @return 所属spu的sku的list
     */
    @Select("SELECT  DISTINCT sku.*  FROM `m_sku` sku,`m_goods_spec_detail` gsd WHERE  gsd.sku_id =sku.id AND gsd.goods_id=#{spuId}")
    List<Sku> getAllSkuBelong2Spu(int spuId);

    @Select("select price from m_sku where id=#{id}")
    BigDecimal getPriceById(int id);

    @Select("select sales from m_sku where id=#{id}")
    int getSalesById(int id);
}
